<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../resource/ystfiles/wapcommon.css">
    <link rel="stylesheet" type="text/css" href="../../resource/ystfiles/fapiao.css">
    <link rel="stylesheet" href="../../resource/ystfiles/weuimin.css">
    <style>
    	body{
    		
    	}
    </style>
</head>
<body>
	<header id="statusBar">
		<div class="header">
			<div class="return">
				<img src="../../image/back.png" tapmode="presshover" style="left: 0" onclick="toindex()">
			</div>
			<div class="tittle">
				普通车主
			</div>
		</div>
	</header>
	<div id="contant" style="height:563px">
		<div class="bg">
			<div style="width:100%" class="w50 fl"><img  id="passiveScan"  class="center" src="../../image/tabBar/ewm_zs.png" style="display: block"><p class="p1 tc">生成二维码</p></div>
		</div>
		<!-- 加载动画 -->
		<div id="loadingToast" style="display:none;">
			<div class="weui-mask_transparent"></div>
			<div class="weui-toast">
				<i class="weui-loading weui-icon_toast"></i>
				<p class="weui-toast__content">数据加载中...</p>
			</div>
		</div>
		<div id="CK_boxs">
		</div>
		<div style="width: 90%" class="FP_btn" onclick="tjCkxx();">
			<a style="display: inline-block;display: -moz-inline-stack;width: 100%;color: #888;" ><strong style="font-size: 20px;">+</strong>&nbsp;手动添加车辆信息</a>
		</div>
	</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../resource/jquery1.js"></script>
<script type="text/javascript" charset="UTF-8" src="../../script/naes.js"></script>
<script type="text/javascript" src="../../script/constants.js"></script>
<script type="text/javascript">
	var xlist;
	apiready = function(){
		api.parseTapmode();
		$api.fixStatusBar($api.dom('header'));
		if(api.systemType=="ios"){
			document.getElementById("statusBar").style.background="#298cb4";
		}
		$("#loadingToast").show();
		api.addEventListener({
			name: 'addCk'
		}, function(ret, err) {
		 	window.location.reload();
		});
		api.addEventListener({
	        name:'delCk'
        },function(ret,err){
        	window.location.reload();
        });
        api.addEventListener({
	        name:'updCk'
        },function(ret,err){
        	window.location.reload();
        });
		var callback = function(ret, err){
		    //console.log(JSON.stringify(ret));
            if (ret) {
	            if(ret.success){
	            	xlist=ret.xlist;
		        	for(var i=0;i<xlist.length;i++){
						var s = "";
						var num = ""; 
						s += "<div class='FP_box clearfix' style='background: #27a8fa;'> "+
						     "	<div onclick='showDetail("+xlist[i].ID+")'  class='fl' style='width: 80%;padding-bottom:18px;'> "+
						     "		<h6><a style='color:#fff '>"+ xlist[i].DRIVER_NAME+"</a></h6> ";

					    if(xlist[i].PLATE_NUM == undefined || xlist[i].PLATE_NUM == "undefined")
					    {
					      num = "无车辆人员";
					    }else{
					      num = xlist[i].PLATE_NUM;
					    }
		    			s += "	<p style='color:#fff;font-size:12px;font-family:微软雅黑;' id='test'>"+num+"</p> "+
		    				 "  </div> "+
		    				 "	<div class='fr' style='margin-top:5px;float:right;font-family: 微软雅黑;'> ";
						var cl_defid = $api.getStorage("cl_defid");
						if(cl_defid=='undefined'||typeof(cl_defid)== "undefined"||cl_defid==null||xlist[i].ID == cl_defid ){
							$api.setStorage("cl_defid",xlist[i].ID);
							s += " 	<a href='javascript:;' class='btn' onclick=''>默认</a> "+
							"	<div>"+
							"</div> ";
						}else{
							s += "	<a href='javascript:;' class='btn' onclick='setDefault(" + xlist[i].ID+ ")'>设置默认</a> "+
							"	<div>"+
							"</div> ";
						}
						$("#CK_boxs").append(s);
		        	}
		        	$("#loadingToast").hide();
	            }else{
	            	$("#loadingToast").hide();
					api.alert({msg:'载入错误！原因：'+ret.msg});
	            }
			 } else {
			    $("#loadingToast").hide();
				api.alert({msg:'载入错误！原因：'+err.msg});
			 } 
	    };
	    var dl_phone = $api.getStorage("dl_phone");
		if (typeof(dl_phone) == "undefined" || dl_phone == "undefined" || dl_phone == "" || dl_phone == null) {
		   api.alert({
				msg: '登录已过期，请重新登录！'
			}, function(ret, err) {
				api.openWin({
					name: '跳转登陆',
					url: '../login.html'
				});
			});
		}else{
			var content = {"dl_phone":dl_phone};
	    	apiAjax(JSON.stringify(content),url.getDriverListInfo,callback);
		}
	};
	
	function setDefault(cl_id){
		$api.setStorage("cl_defid",cl_id);
	    window.location.reload();
	}
	
	function toindex(){
		api.closeWin();
	}
	
	function tjCkxx(){
		api.openWin({
	        name: '添加乘客信息',
	        url: 'addCkInfo.html',
	        pageParam:{
	        	cltj_type : 1
	        }
        });
	}
	function showDetail(id){
		api.openWin({
	        name: '编辑乘客信息',
	        url: 'editCkInfo.html',
	        pageParam:{
	        	cl_id : id,
	        	clck_type : 1
	        }
        });
	}
	$("#passiveScan").click(function(){
		if(xlist.length==0){
			api.alert({msg:"您尚未添加车辆信息，请先添加！"});
			return;
		}else{
			createQrcode();
		}
		
	});
	function createQrcode(){
	 	var cl_defid = $api.getStorage("cl_defid");
		api.openWin({
			name: '车辆二维码信息',
            url: 'CkQRCode.html',
			pageParam: {
				cl_defid:cl_defid
		  }
		});
	}
</script>
</html>